<template>
    <view-box v-if="addBasic" style="background:#F3F6F7">
      <div style="height:10px;"></div>
      <div class="border-store">
        <x-input class="oungt" title="真实姓名:" v-model="addBasic.basic.true_name" v-if="addBasic.basic"  placeholder="请输入真实姓名" is-type="china-name"></x-input>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <x-input class="oungt" title="我的职业:" v-model="addBasic.basic.company" v-if="addBasic.basic"  placeholder="请输入职位" ></x-input>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <x-input class="oungt" title="手机" v-model="addBasic.basic.mobile" v-if="addBasic.basic"   placeholder="手机" is-type="china-mobile"></x-input>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <datetime
            v-model="addBasic.basic.birth"
            title="出生日期:"
            format="YYYY"
            :min-year=1980 
            :max-year=2050
            v-if="addBasic.basic"
           ></datetime>
      </div>
        <div style="height:10px;width:92%;margin-left:4%;"></div>
      <div class="border-store" style="height:50px;line-height:50px;">
         <span style="padding-left:12px;padding-right:12px;color:#AEB1B2;">显示:</span>
        <input type="radio" name="look" v-model="addBasic.basic.true_name_look" v-if="addBasic.basic" value="1">先生
        &nbsp;&nbsp;&nbsp;&nbsp;
        <input type="radio" name="look" v-model="addBasic.basic.true_name_look" v-if="addBasic.basic" value="2">女士
      </div>
      <div style="height:10px;width:100%;"></div>
      <div class="border-store">
        <datetime
          v-model="addBasic.basic.start_work_time"
          title="开始工作:"
          :min-year=1980 
          :max-year=2050
          format="YYYY"
          v-if="addBasic.basic"
        ></datetime>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <x-input class="oungt" title="邮箱:" v-model="addBasic.basic.mailbox" v-if="addBasic.basic"  placeholder="请输入邮箱" is-type="email"></x-input>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <x-input class="oungt" title="id" style="display: none" v-model="addBasic.basic.id" v-if="addBasic.basic"  placeholder="id" is-type=""></x-input>
        <x-address title="地址选择:" class="oungt" v-model="addressValue" raw-value :list="addressData" @on-shadow-change="onShadowChange" value-text-align="right" ></x-address>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <popup-picker title="目前状态:" class="oungt" :data="value12" v-model="typec"  value-text-align="right"></popup-picker>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <popup-picker title="当前年薪:" class="oungt" :data="value6" v-model="annual_salary" v-if="addBasic.basic" value-text-align="right"></popup-picker>
        <p style="text-align: right;padding-right:12px;margin-bottom:10px;">
              <input type="radio" name="salary" v-model="addBasic.basic.is_look_annual_salary" v-if="addBasic.basic" value="1">公开
               &nbsp;&nbsp;&nbsp;&nbsp;
              <input type="radio" name="salary" v-model="addBasic.basic.is_look_annual_salary" v-if="addBasic.basic" value="0">对HR显示为保密
        </p>
        <div style="height:5px;"></div>
      </div>
        <group style="width:92%;margin-left:4%;">
            <x-button style="background:#32B6C6;color:#fff;" @click.native="saveup()">保存</x-button>
        </group>
    </view-box>
</template>
<script>
import { ViewBox, Box, XInput, Group, XButton, Datetime, PopupPicker, ChinaAddressData, XHeader, XAddress, CheckIcon } from 'vux'
export default {
  components: {
    ViewBox,
    Box,
    XInput,
    Group,
    XButton,
    Datetime,
    PopupPicker,
    XHeader,
    XAddress,
    CheckIcon
  },
  data () {
    return {
      addressData: ChinaAddressData,
      radio001: ['是否统招'],
      value4: '',
      value3: '',
      value6: [['1万-2万', '3万-5万', '5万-7万', '7万-10万', '10万-15万', '15万-20万', '200万-25万', '25万-30万', '30万-50万', '50万-100万']],
      addressValue: [],
      annual_salary: [['1万-2万']],
      typec: [['在职，暂无跳槽打算']],
      value1: '',
      value12: [['在职，暂无跳槽打算', '在职，急寻新工作', '离职，正在找工作', '在职，看看新机会']],
      is_unified: false,
      pid: '',
      id: '',
      tabldata: {
        basic: {
          id: '',
          company: '',
          true_name: '',
          mobile: '',
          mailbox: '',
          annual_salary: ''
        }
      },
      addBasic: {},
      addiss: {},
      addpid: '',
      demo2: false,
      demo1: true
    }
  },
  computed: {
    disabled () {
      console.log('zunhh')
    },
    userInfo () {
      return this.$store.getters.userInfo
    }
  },
  mounted () {
    if (!this.$store.state.auth.userInfo) {
      this.$store.dispatch('getUserInfo')
    }
    this._getconm()
    this._getresume()
    this._resetGoodsData()
  },
  created () {
    if (this.$route.query.id !== null) {
      this.id = parseInt(this.$route.query.id)
    }
  },
  methods: {
    _getresume () {
      this.$http.get('/resume').then(response => {
        this.addpid = response.data.id
        if (this.$route.query.id > 0) {
          this.addBasic = response.data
          this.addressValue = [this.addBasic.basic.province, this.addBasic.basic.city, this.addBasic.basic.area]
          this.annual_salary = [this.addBasic.basic.annual_salary]
          this.typec = [this.addBasic.basic.now_status]
        }
        // console.log(this.addressValue)
      }).catch(error => {
        console.log(error)
      })
    },
    _resetGoodsData () {
      this.addBasic = Object.assign({}, this.tabldata)
    },
    change () {
      console.log('zhou')
    },
    saveup () {
      if (this.$route.query.id !== undefined) {
        this.updata()
      } else {
        this.save()
      }
    },
    save () {
      let annualsalarys = String(this.annual_salary)
      let nowstatus = String(this.typec)
      let data = {
        uid: this.userInfo.id ? this.userInfo.id : 0,
        pid: this.addpid,
        company: this.addBasic.basic.company,
        true_name: this.addBasic.basic.true_name,
        mobile: this.addBasic.basic.mobile,
        birth: this.addBasic.basic.birth,
        true_name_look: this.addBasic.basic.true_name_look,
        is_look_annual_salary: this.addBasic.basic.is_look_annual_salary,
        annual_salary: annualsalarys,
        now_status: nowstatus,
        start_work_time: this.addBasic.basic.start_work_time,
        mailbox: this.addBasic.basic.mailbox,
        province: this.addiss.province,
        city: this.addiss.city,
        area: this.addiss.area
      }
      this.$http.post('/resume/storeBasic', data).then(response => {
        this.$vux.toast.show({
          text: response.data.message,
          type: 'text'
        })
        this.$router.push({ path: '/myresume' })
        console.log(response)
      })
    },
    updata () {
      let annualsalarys = String(this.annual_salary)
      let nowstatus = String(this.typec)
      let data = {
        id: this.addBasic.basic.id,
        company: this.addBasic.basic.company,
        true_name: this.addBasic.basic.true_name,
        mobile: this.addBasic.basic.mobile,
        birth: this.addBasic.basic.birth,
        true_name_look: this.addBasic.basic.true_name_look,
        is_look_annual_salary: this.addBasic.basic.is_look_annual_salary,
        annual_salary: annualsalarys,
        now_status: nowstatus,
        start_work_time: this.addBasic.basic.start_work_time,
        mailbox: this.addBasic.basic.mailbox,
        province: this.addiss.province,
        city: this.addiss.city,
        area: this.addiss.area
      }
      this.$http.put('/resume/updateBasic', data).then(response => {
        this.$vux.toast.show({
          text: response.data.message,
          type: 'text'
        })
        this.$router.push({ path: '/myresume' })
        console.log(response)
      }).catch(error => {
        console.log(error)
      })
    },
    setDefaults () {
      console.log(1)
    },
    _getconm () {
      this.$http.post('/entrance').then(response => {
        this.pid = response.data.data.id
      })
    },
    onShadowChange (ids, names) {
      this.addiss = {
        province: names[0],
        city: names[1],
        area: names[2]
      }
    }
  }
}
</script>

<style scoped>
    .btn-set-default {
        flex: 1;
        line-height: 50px;
        
    }
    .border-store{
      width: 92%;
      margin-left: 4%;
      background: #fff;
      border-radius: 7px;
    }
</style>
<style>
.weui-cell_access {
    font-size: 16px;
}
 .weui-cells:before{
        border-top: 0px solid #D9D9D9 !important;
    }
    .weui-cells:after{
        border-bottom: 0px solid #D9D9D9 !important;
    }
    .weui-cell:before {
    border-top: 0px solid #D9D9D9!important;
  }
  .vux-cell-box:not(:first-child):before {
    border-top: 0px solid #D9D9D9!important;
}
.oungt .weui-label {
    display: block;
    width: 105px;
    word-wrap: break-word;
    word-break: break-all;
    color: #AEB1B2;
}
.border-store .vux-datetime {
    color: #AEB1B2!important;
}
</style>
